/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.commons.interconversion;

import java.util.HashMap;

/**
 * enum <=> int 関係を保持する為のmap
 * @author aileron
 *
 */
public class InterconversionMap <T>
{
    /**
     * int map
     */
    private final HashMap<Integer,T> iMap = new HashMap<Integer, T>();
    
    /**
     * enum map
     */
    private final HashMap<T,Integer> eMap = new HashMap<T, Integer>();
    
    /**
     * int <=> enum の関係を設定
     * @param value
     * @param t
     */
    public void set(final int intValue, final T enumValue)
    {
        iMap.put(intValue, enumValue);
        eMap.put(enumValue, intValue);
    }
    
    /**
     * enum から int への変換
     * @param key
     * @return
     */
    public int convert(final T key)
    {
        return eMap.get(key);
    }
    
    /**
     * int から enum への変換
     * @param key
     * @return
     */
    public T convert(final int key)
    {
        return iMap.get(key);
    }
}